<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- 兼容性 -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <title>基础设置-设置权限</title>
    <script src="/scripts/boot.js"></script>
    <style>
        html,body{
            margin:0;padding: 0;border:0;width:100%;height:100%;overflow:hidden;
        }
        body{
            background: #ffffff!important;
            padding:20px;
        }
    </style>
</head>
<body>
<div class="title-list mb-20"><span class="title-listbg"></span><span>权限设置信息</span></div>
<div class="container">
    <div class="mini-clearfix mb-10">
        <div class="mini-col-6 mini-col-sm-3">
            <a class="plan-btn mR-20"  onclick="list.addOrEdit('new')"><span class="add-bg"></span>新增</a>
            <!--<a class="plan-btn mR-20"  onclick="list.addSub()"><span class="add-bg"></span>新增</a>-->
        </div>
    </div>
</div>
<div class="mini-fit">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;"  url="/role/listByPage" sizeList="[5,10,20,50]" pageSize="20"  idField="user_id" multiSelect="true">
        <div property="columns">
            <!--<div type="checkcolumn" headerAlign="center" align="center"></div>-->
            <div type="indexcolumn" headerAlign="center" align="center">编号</div>
            <div field="roleName" width="120" headerAlign="center" align="center" allowSort="false">角色名称</div>
            <div field="userNames" width="120" headerAlign="center" align="center" allowSort="false">人员</div>
            <div field="available" width="120" headerAlign="center" align="center" allowSort="false">是否可用</div>
            <div field="itemNames" width="120" headerAlign="center" align="center" allowSort="false">授权项目</div>
            <div field="createName" width="120" headerAlign="center" align="center" allowSort="false">创建人</div>
            <div field="createDate" width="120" headerAlign="center" align="center" allowSort="false" renderer="ondayRenderer">创建时间</div>
            <div name="action" width="200" headerAlign="center" align="center">操作</div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //list.init();
    var grid;
    var list = {
        //页面初始化
        init: function() {
            mini.parse();
            grid = mini.get("datagrid1");
            grid.load();
            grid.on("drawcell", function (e) {
                var column = e.column;
                var record = e.record;
                if (column.field == "available") {
                    if(e.row.available==0){
                        e.cellHtml ='是'
                    }else{
                        e.cellHtml ='否';
                    }
                }
                if (column.name == "action") {
                    e.cellHtml = '<a class="revise-botton" href="javascript:list.addOrEdit(\''+'edit'+'\')">编辑</a>' +
                        '<a class="del-botton btn-bd" href="javascript:list.remove()">删除</a>' +
                        '<a class="check-botton btn-bd" href="javascript:list.addSub()">资源</a>';
                }
            })
        },
        addSub:function(){
            mini.open({
                url: "/dataBase/authority/add.html",
                title: "新增权限节点", width: 1100, height: 500,
                onload: function () {

                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        },
        //    新增或编辑
        addOrEdit: function (opt) {
            mini.open({
                url: "/dataBase/authority/new.html",
                title: (opt=="edit"?"编辑":"新增")+"角色", width: 1100, height: 450,
                onload: function () {
                    if(opt=="edit"){
                        var row = grid.getSelected();
                        var data = {"id": row.id,"state":opt};
                    }else{
                        var data = {"state":opt};
                    }
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.view.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        },
        //    查看
        view: function(){
            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: "/dataBase/authority/view.html",
                    title: "项目信息", width: 1100, height: 700,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = {"id": row.id};
                        iframe.contentWindow.view.SetData(data);
                    },
                    ondestroy: function (action) {
                        grid.reload();
                    }
                });

            } else {
                mini.alert("请选中一条记录");
            }
        },
        //    查询
        search: function () {
            var data = {
                "name": mini.get("name").getValue(),
                "affiliatedCompanyId": mini.get("affiliatedCompanyId").getValue(),
//            "provinceId": mini.get("provinceCombo").getValue() ? mini.get("provinceCombo").getValue() : 0,
                "cityId": mini.get("cityCombo").getValue(),
//            "regionId": mini.get("regionCombo").getValue() ? mini.get("regionCombo").getValue() : 0,
            };
            grid.load(data);
        },
        //重置
        reset:function(){
            var form = new mini.Form("qForm");
            form.reset();
            grid.load()
        },
        //    删除
        remove: function () {
            var row = grid.getSelected();
            if (row) {
                mini.confirm("确定删除选中记录？","确定",function (action) {
                    if(action=="ok"){
                        $.ajax({
                            url: "/role/del",
                            type : "post",
                            data:{"id":row.id},
                            success: function (text) {
                                if (text.state) {
                                    common.prompt("删除成功！");
                                    grid.reload();
                                } else {
                                    common.prompt(text.message);
                                }
                            },
                            error:function (errorMsg) {
                                var msg  = JSON.parse(errorMsg.responseText);
                                common.prompt(msg.message);
                            }
                        });
                    }
                });
            } else {
                mini.alert("请选中一条记录");
            }
        }
    };
    list.init();
</script>
</body>
</html>